//----------------------------------------------------------------
//					 LaSalle Thesis 2k13 
//	Members:
//
//	Core Engine: Brent Andre Chua codesushi@live.com
//	Tech Director: Leandro Severino Jr. pu_yih@yahoo.com
//-----------------------------------------------------------------


#include "../Framework/Include/WinApp.h"

#include "../Framework/Include/Bitmap.h"
#include "../Framework/Include/BitmapRot.h"
#include "../Framework/Include/BitmapAlpha.h"
#include "../Framework/Include/BitmapMasked.h"
#include "../Framework/Include/Animation.h"


#if defined( _DEBUG )
#pragma comment( lib, "../Debug/Framework.lib" )
#else
#pragma comment( lib, "../Release/Framework.lib" )
#endif 
#pragma comment( lib, "winmm.lib" )

#include "Vector2.h"
#include "Food.h"
#include "SimpleTimer.h"
#include <time.h>
#include "User.h"
#include<fstream>


//#include "FileIO.h"

namespace Pulse
{
	class Camera
	{
	public:

		Camera( float x = 0.0f, float y = 0.0f ) : m_pos( x, y ) { }

		void SetPosition( float x, float y ) { m_pos.x = x; m_pos.y = y; };

		//FPoint & GetPosition( void ) { return m_pos; }

		FPoint * GetPosition( void ) { return &m_pos; }

		void MoveX( float x ) { m_pos.x += x; }

		void MoveY( float y ) { m_pos.y += y; }

		// Translate position to camera's relative position.
		FPoint GetRelativeCamPos( float x, float y ) 
		{
			FPoint ret( x - m_pos.x, y - m_pos.y );
			return ret;
		}

		FPoint GetRelativeCamPos( FPoint point ) 
		{
			FPoint ret( point.x - m_pos.x, point.y - m_pos.y );
			return ret;
		}

	private:
		
		//For the Camera
		FPoint m_pos;

	};
	class MenuButton
	{
	public:

		enum STATE { IDLE, OVER, NUM_STATES };

		MenuButton( const HINSTANCE hInst, const char *pStateIdle, const char *pStateOver );
		
		~MenuButton( void );

		void Update( float mouseX, float mouseY );

		void Render( HDC bbDC, HDC spriteDC );

		void SetPos( float xPos, float yPos ) { m_xPos = xPos; m_yPos = yPos; }

		BOOL IsMenuButtonClicked( void );

	private:

		MenuButton( void );

		float m_xPos, m_yPos;
		Bitmap *m_pStateIdle;
		Bitmap *m_pStateOver;
		STATE	m_state;
	};

	class LaSalle : public WinApp
	{
	public:

		enum Play_STATE { Intro, LogIn, MENU, Play, Credits, Help, Story, HighScore, Exit };

		LaSalle( const HINSTANCE hInst, const CHAR *pStr, const INT posX, const INT posY, const INT width, const INT height );
		virtual ~LaSalle( void );

		virtual BOOL OnStart( void );	
		virtual BOOL OnUpdate( FLOAT dt );
		virtual BOOL OnRender( void );	
		virtual BOOL OnExit( void );		

	private:

		void HandleStateChange( Play_STATE state );

		BOOL OnMenuUpdate( FLOAT dt );
		BOOL OnMenuRender( void );

		BOOL OnPlayUpdate( FLOAT dt );
		BOOL OnPlayRender( void );

		BOOL OnCreditsUpdate( FLOAT dt );
		BOOL OnCreditsRender( void );

		BOOL OnHelpUpdate( FLOAT dt );
		BOOL OnHelpRender( void );

		BOOL OnStoryUpdate( FLOAT dt );
		BOOL OnStoryRender( void );

		BOOL OnExitUpdate( FLOAT dt );
		BOOL OnExitRender( void );		

		BOOL OnLogInUpdate( FLOAT dt);
		BOOL OnLogInRender( void );

		BOOL OnHighScoreUpdate( FLOAT dt );
		BOOL OnHighScoreRender(void);

		BOOL PopUpUpdate( FLOAT dt);
		BOOL PopUpRender(HDC bbDC, int PopUp );

		void IsGameOver( void );
		void SaveLoad(void);
		
	private:

		enum GameCategory
		{
			NONE,
			EASY,
			MEDIUM,
			HARD			
		};	

		int mGameCategory;		
		Play_STATE m_PlayState;
		float m_FishPosX, m_FishPosY;
        //------------------------------------
        //Main Menu Screen Elements
        //-------------------------------------
        Bitmap *m_pMainMenuBackground;
		BitmapMasked *m_pCreditsBackground;
        Bitmap *m_pHelpBackground;
		Bitmap *m_pReviewBackground;
		Bitmap *m_pReviewBackground2;
		Bitmap *m_pReviewBackground3;



        MenuButton		*m_pPlayMenuButton;
		MenuButton		*m_pCreditsMenuButton;
		MenuButton		*m_pHelpMenuButton;
		MenuButton		*m_pExitMenuButton;
		MenuButton		*m_pCredihMenuButton; //Credih

		Sound ButtonClick;
		Sound MainMenuSound;
		Sound EatLetters;
		Sound waterloop1;

		//----------------------------------------
		//LogIn Screen
		//---------------------------------------
		//char mUserName[11];		
		Player mPlayer;
		Bitmap *m_pLogInBackGround;
		
		//-----------------------------------------
		//Play Screen
		//-----------------------------------------
		Animation *m_pMovingGreenFish;
		Animation *m_pMovingGreenFish2;
		float mLastPosX;
		String mJumbledWord;

		float m_posX1, m_posY1; //x,y pos of the fish
		float mGameTimer;
		int mLives;
		int mCorrectAnswers;
	
		BitmapMasked *mpFishLives;
		float speedy;
		bool accept;
		Bitmap *m_pBackGround;
		Bitmap *m_pFood;
		Bitmap *m_pFood_A;
		
		Food mFishFood;
		Food mFishFoodB;
		Food mFishFoodC;
		Food mFishFoodD;
		Food mFishFoodE;
		Food mFishFoodF;
		Food mFishFoodG;
		Food mFishFoodH;
		Food mFishFoodI;
		Food mFishFoodJ;
		Food mFishFoodK;
		Food mFishFoodL;
		Food mFishFoodM;
		Food mFishFoodN;
		Food mFishFoodO;
		Food mFishFoodP;
		Food mFishFoodQ;
		Food mFishFoodR;
		Food mFishFoodS;
		Food mFishFoodT;
		Food mFishFoodU;
		Food mFishFoodV;
		Food mFishFoodW;
		Food mFishFoodX;
		Food mFishFoodY;
		Food mFishFoodZ;
		Food mSpace;

		int isVisible[27];
		int RanOne;
	
		//QUESTIONS
		int TotalQuestionsFromFile;
		String (*	WORDS)[2];
		int totalEasyQuestions;
		int totalMediumQuestions;
		int totalHardQuestions;

		String mWordToGuess;
		String mQuestion;
		char mQuestionToShow[100];
		bool mResetQuestion;
		int mNumOfQuestions;
		//ANSWERS
		//Answer Rendered on the screen
		char mPlayerAnswer[15]; 
		char mEngine[100];
		char mEngine2[100];
		BitmapMasked *letters[27];

		BitmapMasked *SpecialChar[10];
		INT AnsIndex;
		String Ex;
		String  Alphabet;

		BOOL mStartGame;
		BOOL getInputFile;//ifstream/ofstream
		BOOL getOutPutFile;
		BOOL stopOutFile;

		//------------------
		//PopUps
		//------------------
		Bitmap *m_pGameOverPopUp;
		Bitmap *m_pCorrectAnswer;
		Bitmap *m_pWrongAnswer;
		Bitmap *m_pLevelOneComplete;
		Bitmap *m_pLevelTwoComplete;
		Bitmap *m_pLevelThreeComplete;
		
		BOOL ShowPopUpCorrectAnswer;
		BOOL ShowPopUpWrongAnswer;
		BOOL ShowPopUplevel1Complete;
		BOOL ShowPopUplevel2Complete;
		BOOL ShowPopUplevel3Complete;
		float popuptimer; //now used for fish face dir
		//Bitmap *Score;

		//--------------------
		//HighScore Screen
		//--------------------
		Bitmap *m_pHighScoreBg;
		int mScore;		

		int MyHighScore;
		int HSCORE[12];//but only show top 10

		char TopOne[7];		

		float Credih ;
		bool BckTomain;

		int Review;
		
        Camera m_cam;
	};

	PSX_INLINE Pulse::BOOL PointRectCollisionCheck( POINT &pnt, RECT &r )
	{
		return pnt.x >= r.left && pnt.x <= r.right && pnt.y >= r.top &&  pnt.y <= r.bottom;
	}
	Pulse::BOOL RectToRectCollision( RECT &r1, RECT &r2, Vector2 &pushVec  );
	Pulse::BOOL RectToSphereCollision( RECT &r, FPoint &ball, FLOAT radius, Vector2 &pushVec );
}